<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分类数据测试</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            color: #333;
        }
        h1, h2, h3 {
            color: #2c3e50;
        }
        .debug-info {
            background-color: #fff3cd;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 20px;
            border: 1px solid #ffeaa7;
        }
        .category-list {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 15px;
            margin-bottom: 30px;
        }
        .category-item {
            background-color: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            border: 1px solid #dee2e6;
        }
        .category-item h4 {
            margin-top: 0;
            color: #2c3e50;
        }
        .first-level-list {
            background-color: #e7f3ff;
            padding: 20px;
            border-radius: 8px;
        }
        .first-level-item {
            padding: 10px 15px;
            margin-bottom: 8px;
            background-color: #ffffff;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        .first-level-item:hover {
            background-color: #d1e0ff;
        }
    </style>
</head>
<body>
    <h1>分类数据测试页面</h1>
    
    <!-- 调试信息 -->
    <div class="debug-info">
        <h3>调试信息</h3>
        <p>分类数据是否存在: <span id="data-exists"></span></p>
        <p>分类数据数量: <span id="data-count"></span></p>
        <p>一级分类数量: <span id="first-level-count"></span></p>
    </div>
    
    <!-- 所有分类列表 -->
    <div>
        <h2>所有分类</h2>
        <div class="category-list" id="all-categories"></div>
    </div>
    
    <!-- 一级分类列表 -->
    <div class="first-level-list">
        <h2>一级分类</h2>
        <div id="first-level-categories"></div>
    </div>

    <script>
        // 模拟分类数据 - 与Vue组件中相同的数据
        const mockCategories = [
            {
                id: 1,
                name: '电子产品',
                parentId: 0,
                subTitle: '各类电子设备',
                icon: 'icon-electronics'
            },
            {
                id: 2,
                name: '手机',
                parentId: 1,
                subTitle: '智能手机',
                icon: 'icon-phone'
            },
            {
                id: 3,
                name: '电脑',
                parentId: 1,
                subTitle: '笔记本和平板',
                icon: 'icon-computer'
            },
            {
                id: 4,
                name: '家居用品',
                parentId: 0,
                subTitle: '家庭生活用品',
                icon: 'icon-home'
            }
        ];

        // 输出调试信息
        document.getElementById('data-exists').textContent = mockCategories && mockCategories.length > 0 ? '是' : '否';
        document.getElementById('data-count').textContent = mockCategories ? mockCategories.length : 0;

        // 过滤一级分类
        const firstLevelCategories = mockCategories.filter(item => item.parentId === 0);
        document.getElementById('first-level-count').textContent = firstLevelCategories.length;

        // 渲染所有分类
        const allCategoriesContainer = document.getElementById('all-categories');
        mockCategories.forEach(category => {
            const item = document.createElement('div');
            item.className = 'category-item';
            item.innerHTML = `
                <h4>${category.name}</h4>
                <p>ID: ${category.id}</p>
                <p>父ID: ${category.parentId}</p>
                <p>层级: ${category.parentId === 0 ? '一级分类' : '二级分类'}</p>
                <p>副标题: ${category.subTitle || '无'}</p>
            `;
            allCategoriesContainer.appendChild(item);
        });

        // 渲染一级分类
        const firstLevelContainer = document.getElementById('first-level-categories');
        firstLevelCategories.forEach(category => {
            const item = document.createElement('div');
            item.className = 'first-level-item';
            item.textContent = category.name;
            firstLevelContainer.appendChild(item);
        });

        console.log('模拟分类数据:', mockCategories);
        console.log('一级分类过滤结果:', firstLevelCategories);
    </script>
</body>
</html>